--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
--
--  file:    mobilesOrders.lua
--  brief:   Handles the noncontrolled unit groups that are produced by factories (needs to be somewhat player specific ?)
--  author:  Sean Heron
--
--  Copyright (C) 2009.
--  Licensed under the terms of the GNU GPL, v2 or later.
--
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------

function gadget:GetInfo()
  return {
    name      = "mobilesOrders",
    desc      = "Give orders to non controlled mobile units",
    author    = "Sean Heron",
    date      = "September 3rd, 2009",
    license   = "GNU GPL, v2 or later",
    layer     = 1,
    enabled   = true
  }
end


local hunchback   = UnitDefNames.hunchback.id


if (gadgetHandler:IsSyncedCode()) then    -- seems it needs to be synced... ?     buh

--  SYNCED    
--------------------------------------------------------------------------------

local mobiles ={hunchback,

				}

local newunits ={}

--function gadget:Update()                      -- why no go ? just use Gameframe I guess then (like everyone does...)
--	if (newunits) then
--		Spring.Echo("Some units ready?!")
--		for _,unitID in pairs(newunits) do                     -- will need to differentiate by team - either in UnitFromFactory, or with if statements here
--			Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {2000,0,3300}, {})
--		end
--		newunits = {}
--	end
--end




function gadget:UnitFromFactory(unitID, unitDefID, unitTeam, factID, factDefID, userOrders)

	for _,toorder in pairs(mobiles) do
        if (unitDefID == toorder) then
        table.insert(newunits,unitID)
		end
	end
end


function gadget:GameFrame(f)
	if (f % 30 == 0) then              -- vill zis vork ? JAA!
--		Spring.Echo("Some units ready?!")
		for _,unitID in pairs(newunits) do                     -- will need to differentiate by team - either in UnitFromFactory, or with if statements here
			Spring.GiveOrderToUnit(unitID, CMD.FIGHT, {2000,0,3300}, {"shift"})
			Spring.Echo(unitID)
		end
		newunits = {}
	end

end


----------------------------------------------------------------------------------
---- UNSYNCED               -- do I care ? am I busting something, would it work in Unsynced but I'm doing it wrong ?
----------------------------------------------------------------------------------
				-- need to doodle some and see if this runs at all... (ah, perhaps only with draw.lua... ? maybe that's the problem all along? ??!

end